<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <title>WIFI信息展示</title>
        
        <link rel="stylesheet" type="text/css" href="../css/cm-default.css"  />
        <link rel="stylesheet" type="text/css" href="../ligerUI/skins/Aqua/css/ligerui-all.css" />
        <link rel="stylesheet" type="text/css" href="../ligerUI/skins/ligerui-icons.css" />
        <script src="../js/jquery-min.js" type="text/javascript"></script>
        <script src="../ligerUI/js/ligerui.min.js" type="text/javascript"></script>
        <script src="../js/common.js" type="text/javascript"></script>
        <script src="../js/json2.js" type="text/javascript"></script>
        <script type="text/javascript" src="../js/md5.js"></script>
        <script src="../js/validate/jquery.validate.js" type="text/javascript"></script>
        <script src="../js/validate/jquery.metadata.js" type="text/javascript"></script>
        <script src="../js/validate/messages_zh.js" type="text/javascript"></script>
        <script type="text/javascript">
            var defGrid,Wifi_Useable,shop_No,addDialog;
            var wifiNo;
            $(function(){
                $("#layout_main").ligerLayout({
                });
                defGrid = $("#query_list").ligerGrid({
                    columns:[
                        {display:'广告编号',name:'advertise_no',width:120,align:'left'},
                        {display:'广告名称',name:'advertise_name',width:120,align:'left'},
                        {display:'文件名称',name:'file_name',width:120,align:'left',render:function(rowdata,rowindex,value){
                        	if(value == 'null' || value =='')value = '';
                            return "<a href='javascript:void(0);' class='opt-link' onclick='download_file(" + rowindex + ")'>"+value+"</a>";}},
                        {display:'广告有效期',name:'advertise_date',width:120,align:'left'},
                        {display:'广告级别',name:'advertise_level',width:120,align:'left',render:function(item){return paramRender(item,'ad_level',item.advertise_level);}},
                        {display:'是否有效',name:'advertise_useable',width:120,align:'left',render:function(item){return paramRender(item,'rbac.status',item.advertise_useable);}},
                        {display:'wifi名称(ssid)',name:'wifi_ssid',width:100},
                        {display:'商户编号',name:'shop_no',width:120,align:'left'},
                        {display:'商户名称',name:'shop_name',width:120,align:'left'},
                    ],
                    pageSize:10,
                    usePager: true,
                    sortName:'id',            
                    dataAction:'server',
                    url: '../common/q.jsp',                     
                    width:'100%',
                    height:'99%',
                    checkbox:false,
                    rownumbers:false,
                    fixedCellHeight:false,
                    colDraggable:true,
                    enabledEdit:true,
                    clickToEdit:false,
                    onSelectRow:function(rowdata, rowindex){$("#txtrowindex").val(rowindex);},
                    onReload: toQuery,
                    onToFirst: function(item) {
                        toQuery(item, 1);
                    },
                    onToLast: function(item) {
                        var p = parseInt(defGrid.options.total / defGrid.options.pageSize);
                        if (defGrid.options.total % defGrid.options.pageSize > 0)
                            p += 1;
                        toQuery(item, p);
                    },
                    onToPrev: function(item) {
                        var p = parseInt(defGrid.options.page);
                        if (p > 1)
                            p -= 1;
                        else
                            return;
                        toQuery(item, p);
                    },
                    onToNext: function(item) {
                        var p = parseInt(defGrid.options.total / defGrid.options.pageSize);
                        if (defGrid.options.total % defGrid.options.pageSize > 0)
                            p += 1;
                        var cp = parseInt(defGrid.options.page); 
                        if (cp < p)
                            cp += 1;
                        toQuery(item, cp);
                    }
                });
                appendAddBtn(openDictDef, "添加广告信息");
                appendModifyBtn(openModify, "修改广告信息");
                appendDeleteBtn(deleteRow, "删除广告信息");
                $("#pageloading").hide();
                //默认查询全部数据 
                toQuery();
            });

            //查询
            function toQuery(item, page, pageSize) {
                if (!page)
                    page = defGrid.options.page;
                if (!pageSize)
                    pageSize = defGrid.options.pageSize;
                
                var param = new Object();
                param.wifi_ssid = $("#wifi_ssidQ").val();
                param.shop_name = $("#shop_nameQ").val();
                param.advertise_name = $("#advertise_nameQ").val();
                var data = JSON.stringify(reqObj('q','wifi.select.advertise_shop_info.query',JSON.stringify(param),'l',true,page,pageSize));
                ajaxSubmit("/cmwifi/rbac/cm.do?m=q", data, function(data) {
                    var d = data['data'].Rows;
                    var ps = defGrid.options.pageSize, p = defGrid.options.page, t = parseInt(data['data'].Total);
                    if (t > ps) {
                        for (var i = 0; i < (p - 1) * ps; i++) {
                            d.unshift(null);
                        }
                    }
                    defGrid.data = data['data'];
                    defGrid.set({data: data['data']});
                });
            }
             
            function openDictDef() {
//                 addDialog = $.ligerDialog.open({height:500,width:700,isResize:true,url:'./add_adertise_basic_info.html',title:'新增广告信息'});
//                 return false;
                parent.f_addTab('add_advertise_info','新增广告信息','./wifiInfo/add_adertise_info.html');
            }
            //编辑
            function openModify() {
                var row = defGrid.getSelectedRow();
                if (!row) {
                    $.ligerDialog.error('请先选择广告记录。','错误');
                    return;
                }
                modifyDialog = $.ligerDialog.open({height:500,width:700,isResize:true,url:'./add_adertise_basic_info.html?o=m&code='.concat(row.advertise_no),title:'修改广告信息'});
            }
            function deleteRow(rowid) {
                
                var row = defGrid.getSelectedRow();
                 if (!row) {
                   $.ligerDialog.error('请先选择要删除的广告记录。','错误');
                   return;
                  }                
                   $.ligerDialog.confirm('您确定要删除该项数据吗？', function(r) {
                       if (!r)
                           return;
                        toDel(JSON.stringify(row));
                       defGrid.deleteRow(rowid);
                   })
               }
            function toDel(row) {
                var param = JSON.stringify(reqObj('d','wifi.delete.adertise_basic_info.delete',row));
                   ajaxSubmit("/cmwifi/rbac/cm.do?m=d", param, function(data) {
                       if (data) {
                           if (parseInt(data['status']) > 0) {
                               toQuery();
                               $.ligerDialog.success('删除成功');
                           } else {
                               $.ligerDialog.error('删除失败');
                           }
                       }
                   });
           }
            function download_file(rowid){
            	var advertise_no = defGrid.getRow(rowid)['advertise_no'];
                if (advertise_no) {
                	window.open("../rbac/impFile.do?method=download&advertise_no="+advertise_no);
                }
            }
        </script>
        <style type="text/css">
            label{margin: 5px 20px 5px 15px;}
            .fields{height:35px;padding-top:5px;}
            .dict-info{width: 260px;padding: 10px;}
            .diff {margin:3px 0;}
            .lineD {width:99%;float:left;position:relative;overflow:hidden;margin:10px 0 2px 2px}
            .labelD {width:26%;position:relative;float:left;padding-top:3px;}
            .dplD {width:73%;position:relative;float:left;}
            .title{font-size:14px;font-weight:bold;background-position:left;padding-left:18px;}
        </style>
    </head>
    <body style="padding:0;">
        <div id="pageloading"></div>  
        <div id="layout_main">
            <div position="center" id="a_center" title="菜单列表">
                <div id="query_cond" class="fields">
                    <label>WIFI名称(ssid)</label><input type="text" class="s-text txt-def" id="wifi_ssidQ" />
                    <label>广告名称</label><input type="text" class="s-text txt-def" id="advertise_nameQ" />
                    <label>商户名称</label><input type="text" class="s-text txt-def" id="shop_nameQ" />
                    <input type="button" value="查询" style="margin-left:25px;" onclick="toQuery();" />
                    <input type="button" value="清空" onclick="toReset('#query_cond input,select,textarea');" />
                </div>
                <div id="query_list"></div>
            </div>
        </div>
    </body>
</html>